package com.tangyuan.video.controller;

import com.tangyuan.common.result.Result;
import com.tangyuan.common.result.ResultCodeEnum;
import com.tangyuan.model.Video;
import com.tangyuan.video.service.VideoService;
import com.tangyuan.video.service.VideoThumpService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

@RestController
@RequestMapping("/video")
public class VideoController {

    @Autowired
    VideoService videoService;
    @Autowired
    VideoThumpService videoThumpService;

    @PostMapping("/topMyVideo")
    public Result topMyVideo(@RequestHeader(name = "userId", required = false) Long userId, @RequestParam("videoId") Long videoId) {
        return videoService.topMyVideo(videoId, userId);
    }
    //视频点赞及取消点赞
    @GetMapping("/addthump")
    public Result addVideoThumpById(@RequestHeader(name = "userId", required = false) Long userId, @RequestParam("videoId") Long videoId) {
        return videoThumpService.addVideoThump(videoId, userId);
    }

    //根据视频id获取视频
    @GetMapping("/getVideoById")
    public Result<Video> getVideoById(@RequestHeader(name = "userId", required = false) Long userId, @RequestParam("videoId") Long videoId) {
        return Result.ok(videoService.getVideoById(videoId, userId));
    }

    //根据视频id删除视频
    @PostMapping ("/deleteById")
    public Result<ResultCodeEnum> deleteById(@RequestHeader(name = "userId", required = false) Long userId, @RequestParam("videoId") Long videoId) {
        return videoService.deleteById(videoId, userId);
    }
}
